﻿using System;

class NarcissisticNumbers
{
    static void Main()
    {
        Console.WriteLine("1000以内的水仙花数有：");
        
        // 遍历1到999的所有数
        for (int num = 1; num < 1000; num++)
        {
            int original = num;
            int sum = 0;
            int digits = 0;
            int temp = original;
            
            // 计算数字的位数
            if (temp == 0)
                digits = 1;
            else
                for (; temp != 0; temp /= 10, digits++) ;
            
            // 计算各位数字的n次方之和
            temp = original;
            for (; temp != 0; temp /= 10)
            {
                int digit = temp % 10;
                int power = 1;
                
                // 计算digit的digits次方
                for (int i = 0; i < digits; i++)
                {
                    power *= digit;
                }
                
                sum += power;
            }
            
            // 判断是否为水仙花数
            if (sum == original)
            {
                Console.Write($"{original} ");
            }
        }
        
        Console.WriteLine();
    }
}